<template>
  <base-page-view ref="pageView" class-name="order-result-container">
    <base-nav :title="title" background="#E21536" title-color="white">
      <view slot="left" class="header-left" @click="handelBack">
        <image src="/static/images/icon/icon_return_white.png" />
      </view>
    </base-nav>
    <view v-if="orderObject" class="order-succeed">
      <view class="order-succeed-container">
        <view class="text">
          <b-image src="/static/images/order/pay_succeed_icon.png" width="100" height="100" />
          <view v-if="member_pay_select&&member_pay_select.goods">
            支付成功，{{memberTxt}}会员商品礼包券到账可能存在延迟
          </view>
          <view v-else>
            支付成功，{{memberTxt}}会员
          </view>
        </view>
        <view class="btnRow">
          <text class="o-span" @click="payDetail">支付详情</text>
          <text class="o-span theme" v-if="member_pay_select&&member_pay_select.goods" @click="useGoods">立即提货礼包券</text>
          <text class="o-span theme" v-else @click="$navigateTo('/pagesMember/member/index')">会员中心</text>
        </view>
      </view>
      <view v-if="tipShow" class="tip-con">
        <image class="tip-con-icon" src="/static/images/order/icon_message.png"></image>
        凡是自称快递、商家客服主动联系您购物退款，都是诈骗！
      </view>
      <view v-if="show" class="moreProduct">
        <view class="o-p">- 猜您喜欢 -</view>
        <view class="o-small">ALL THE GOODS</view>
        <likeList ref="likeListRef" image-radius="0" :from="orderObject.type===260? 'h5_gift' : ''" @getCommendData="getCommendData" />
      </view>
    </view>
  </base-page-view>
</template>

<script>
import { getOrderState } from '@/utils/common'
import { getUserLevel } from '@/utils/common'
import { parseTime, inputCheckNumber, formatUrlParam, throttle, getQueryString } from '@/utils/tools'
import { toFunctionDetail } from '@/utils/navigateTo'
import { navigateToMiniProgram, toMpHomePage, pageNavigateBack } from '@/utils/navigateTo'
import likeList from '@/components/likeGoodsList/index'
import './index.scss'
import { mapGetters } from 'vuex'
import sku_pay_mixin from '@/pagesMember/components/sku_pay_mixin.js'
export default {
  name: 'OrderSucceed',
  mixins: [sku_pay_mixin],
  components: {
    likeList
  },
  data() {
    return {
      title: '支付成功',
      shareOption: {}, // 分享自定义设置
      orderObject: {},
      query: {},
      orderNo: '',
      show: true,
      showAdPopup: false,
      tipShow: true ,// 是否显示诈骗提示
      goods_id:"",//商品编号
      member_pay_select:"",//会员支付选择礼包券
      memberType:"",//会员类型
    }
  },
  computed: {
    ...mapGetters(['extraData']),
    memberTxt(){
      let title="";
      if(this.memberType){
        switch (this.memberType.toLocaleLowerCase()){
          case "vip":
            title="VIP";
            break;
          case "diamond":
            title="钻石";
            break;
          default:
            break;
        }
      }
      return title;
    }
  },
  onLoad(options) {
    this.orderNo = options.orderNo;
    this.goods_id = options.goods_id;
    this.memberType=options.type;
    this.query = {
      ...options
    }
    this.member_pay_select=uni.getStorageSync('member_pay_select');//会员支付选择礼包券
    console.log(this.member_pay_select);
  },
  onShow() {
  },
  onShareAppMessage(res) {
    return this.$queryShareOption(res, this.shareOption)
  },
  onReachBottom() {
    this.$refs.likeListRef.loadMore()
  },
  onPageScroll(res) {
    this.$refs.pageView.scrollShowBtn(res)
  },
  methods: {
    //跳转支付详情
    payDetail() {
      this.$navigateTo(`/pagesMember/payDetail/index?orderNo=${this.orderNo}`)
    },
    //使用商品券
    useGoods(){
      if(!this.member_pay_select){return};
      let goods=this.member_pay_select.goods;
      //直接跳转下单页,mixin混入
      this.go_order_pay({
        goods:goods
      });
    },
    getCommendData(show) {
      this.show = show;
    },
    handelBack() {
      if (this.extraData && this.extraData.platform) {
        navigateToMiniProgram({
          success: () => {
            console.log('返回成功')
            this.$store.dispatch('setExtraData', null)
            toMpHomePage()
          }
        })
      } else {
        pageNavigateBack()
      }
    },
    // 分享初始化
    initShare() {
      if (this.orderObject && this.orderObject.successPay && this.orderObject.status !== 1 && this.orderObject.successPay.shareResponse) {
        const shareResponse = this.orderObject.successPay.shareResponse
        let share_url = ''
        if (shareResponse.url.match('#')) {
          share_url = shareResponse.url.split('#')[1]
        } else {
          share_url = shareResponse.url.split('bisinuolan.cn')[1]
        }
        this.shareOption.share_title = shareResponse.title
        this.shareOption.share_content = shareResponse.content
        this.shareOption.share_url = share_url
        this.shareOption.share_icon = shareResponse.pic
        this.shareOption.share_image = shareResponse.pic
        this.showShare()
      } else {
        this.hideShare()
      }
    }
  }
}

</script>

